package com.fc.service.impl

import java.util.List;

import org.hibernate.Criteria
import org.hibernate.criterion.Restrictions
import org.springframework.stereotype.Repository
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.fc.service.WorkoutJournalService
import com.fc.entities.User;
import com.fc.entities.WorkoutJournal

@Service("workoutJournalService")
@Transactional
class WorkoutJournalServiceImpl extends BaseServiceImpl<WorkoutJournal> implements WorkoutJournalService {
	@Override
	List<WorkoutJournal> findAllByDate(Date date) {
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		c.add(Calendar.DATE, 1);
		Date nextDay = c.getTime();
		
		Criteria criteria = currentSession().createCriteria(WorkoutJournal.class);
		criteria.add(Restrictions.between('date', date, nextDay));
		List<WorkoutJournal> list = criteria.list();

		return list;
	}
	
	List<WorkoutJournal> findAll() { 
		findAll(WorkoutJournal.class)
	}

	@Override
	List<WorkoutJournal> findAllByUser(User user) {
		Criteria criteria = currentSession().createCriteria(WorkoutJournal.class);
		criteria.add(Restrictions.eq("user", user));
		List<WorkoutJournal> list = criteria.list();
	}
	
	@Override
	WorkoutJournal find(Class<WorkoutJournal> tclazz, long id) {
		WorkoutJournal wj = super.find(tclazz, id);
		wj.workout.workoutEntries
		wj.workout.workoutEntries.each {
			it.activity
		}
		return wj
	} 
}
